package com.easyexcel.usr.util;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Package: com.easyexcel.usr.util
 * @ClassName: WriteForead
 * @Author: shuaijun Wang
 * @CreateTime: 2020/11/5 14:21
 * @Description:
 */
public class WriteForeadUtils {
    /**
     * 提供返回结果
     *
     * @param message
     * @return
     */
    public static void getResultObject(HttpServletResponse response, String message) {
        try {
            response.setStatus(504);
            response.setCharacterEncoding( "UTF-8" );
            response.setContentType( "application/json; charset=utf-8" );
            JSONObject res = new JSONObject(){
                {
                    put( "code", 504);
                    put( "msg", message );
                }
            };
            PrintWriter out = response.getWriter();
            out.write( res.toString() );
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
